package com.example.tests;

import java.util.Collections;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.Test;

public class ContactCreationTests extends TestBase{

  //@Test
  public void testNonEmptyContactCreation() throws Exception {
	  app.getNavigationHelper().openMainPage();
	  app.getContactHelper().initContactCreation();	  
	  ContactData contact = new ContactData();
	  contact.firstName = "Name 1";
	  contact.lastName = "Name 2";
	  app.getContactHelper().fillContactForm(contact);
	  app.getContactHelper().submitContactCreation();
	  app.getContactHelper().returnToHomePage();
	  
  }

  //@Test
  public void testEmptyContactCreation() throws Exception {
	  app.getNavigationHelper().openMainPage();
	  app.getContactHelper().initContactCreation();	  
	  app.getContactHelper().fillContactForm(new ContactData("", "", "", "", "", "", "", "", "", "", "", "", ""));	  
	  app.getContactHelper().submitContactCreation();
	  app.getContactHelper().returnToHomePage();
  }
  
  @Test
  public void testContactCreationWithAllFields() throws Exception {
	  app.getNavigationHelper().openMainPage();
	  
	  List<ContactData> oldList = app.getContactHelper().getContacts();
	  
	  app.getContactHelper().initContactCreation();
	    
	  ContactData contact = new ContactData();
	  contact.firstName = "Ivan";
	  contact.lastName = "Ivanov";
	  contact.address = "Komsomolskaya street";
	  contact.homeNumber = "111-222";
	  contact.mobileNumber = "+7-911-111-11-11";
	  contact.workNumber = "222-333";
	  contact.email = "ivan@ivan.ivan";
	  contact.email2 = "ivan2@ivan.ivan";
	  contact.bday = "1";
	  contact.bmonth = "December";
	  contact.byear = "1900";
	  contact.group = "group name 1";
	  contact.address2 = "one more address";
	  contact.phone2 = "home";
    
      app.getContactHelper().fillContactForm(contact);	 
      app.getContactHelper().submitContactCreation();      
      app.getContactHelper().returnToHomePage();
      
      List<ContactData> newList = app.getContactHelper().getContacts();
      
      oldList.add(contact);
	  Collections.sort(oldList);
	  Collections.sort(newList);
	  Assert.assertEquals(newList, oldList);
  }
}
